1
The Foundations of Counting
MATH002 Lesson 6
00:00
Counting is the art of determining the size of finite sets without the tedious labor of physical enumeration. By leveraging logical structures, we can solve problems ranging from simple menu combinations to complex cryptographic permutations.

The Logic of "OR" and "AND"

Two pillars support the entire field of combinatorics. Their application depends entirely on whether we are viewing a task as a single choice from multiple categories or a sequence of choices.

The Addition Principle (Rule of Sum)

If a set $X$ is partitioned into disjoint subsets $X_1, X_2, \dots, X_n$, then the total number of elements $|X|$ is the sum of the sizes of those subsets:

$$|X| = |X_1| + |X_2| + \dots + |X_n|$$

Analogy: Choosing a meal at Kay’s Quick Lunch by picking either a sandwich from the Main Course menu OR an appetizer from the Appetizer menu. You cannot have both; you choose one item.

The Multiplication Principle (Rule of Product)

If an activity consists of $t$ successive steps, where step $i$ has $n_i$ possible outcomes, the total number of ways to complete the task is the product of the possibilities at each step:

$$N = n_1 \times n_2 \times \dots \times n_t$$

Analogy: Configuring a "Big Pickup" truck. You must choose an engine (5 options) AND a cab style (3 options). The total configurations equal $5 \times 3 = 15$.

Code Implementation and Complexity

In computer science, these principles manifest in loop structures. Sequential loops represent the Addition Principle, while nested loops represent the Multiplication Principle.

// Addition Principle (m + n executions)
for i = 1 to m: println(i)
for j = 1 to n: println(j)

// Multiplication Principle (m * n executions)
for i = 1 to m:
  for j = 1 to n:
    println(i, j)
🎯 Core Principle
Distinguish by keywords: "OR" signifies Addition (mutually exclusive choices), while "AND" or "Successive" signifies Multiplication (independent steps in a sequence).